package com.suray.attendance.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suray.attendance.db.mapper.ErpOperationInfoMapper;
import com.suray.attendance.db.service.ErpOperationInfoDBService;
import com.suray.attendance.model.pojo.ErpOperationInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


/**
 * <p>
 *  服务实现类
 * </p>
 * @author jly
 * @since 2023-09-20
 */
@Service
public class ErpOperationInfoDBServiceImpl extends ServiceImpl<ErpOperationInfoMapper, ErpOperationInfo> implements ErpOperationInfoDBService {


    /**
     * @Description: 根据工艺编号获取工艺id
     * @Param: [operationCode]
     * @return: com.suray.attendance.model.pojo.ErpOperationInfo
     * @Author: jly
     * @Date: 2023/11/29
     */
    @Override
    public ErpOperationInfo getIdByOperationCode(String operationCode) {
        if(StringUtils.isEmpty(operationCode)){
            throw new RuntimeException("查询工艺信息参数为空");
        }else {
            ErpOperationInfo erpOperationInfo = baseMapper.selectOne(new LambdaQueryWrapper<ErpOperationInfo>().eq(ErpOperationInfo::getOperationCode, operationCode));
            if(erpOperationInfo == null || StringUtils.isEmpty(erpOperationInfo.getOperationId())){
                throw new RuntimeException("根据工艺编号"+operationCode+"查询工艺信息id失败");
            }else {
                return erpOperationInfo;
            }
        }
    }

    /**
     * @param operationId
     * @Description: 根据工艺id获取工艺名称
     * @Param: [operationId]
     * @return: void
     * @Author: jly
     * @Date: 2023/11/29
     */
    @Override
    public ErpOperationInfo getOperationNameById(String operationId) {
        if(StringUtils.isEmpty(operationId)){
            throw new RuntimeException("查询工艺信息id参数为空");
        }else {
            ErpOperationInfo erpOperationInfo = baseMapper.selectById(operationId);
            if(erpOperationInfo == null || StringUtils.isEmpty(erpOperationInfo.getOperationId())){
                throw new RuntimeException("根据工艺id"+operationId+"查询工艺名称失败");
            }else {
                return erpOperationInfo;
            }
        }
    }
}
